package com.candy.demo;

import java.sql.*;
import java.util.Scanner;

public class JDBCDemo3 {
    public static void main(String[] args) throws Exception{
        Class.forName("com.mysql.jdbc.Driver");
        //2.获取连接对象
        String url="jdbc:mysql://localhost:3306/test1";
        String username = "root";
        String password = "root";
        Connection conn = DriverManager.getConnection(url,username,password);

        Scanner sc = new Scanner(System.in);
        String user=sc.nextLine();
        String pass = sc.nextLine();
        String sql ="select * from users where uname=? and password=?";
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setString(1,user);
        ps.setString(2,pass);

        ResultSet rs= ps.executeQuery();
        while (rs.next()){
            System.out.println(rs.getString("uname")+"   "+rs.getString("password"));
        }
        rs.close();
        ps.close();
        conn.close();
    }
}
